@model DNA.Mvc.WebPage
@{
    var context = WebSiteContext.Current;
}
@using (Html.BeginForm())
{
    if ((Model == null) || (Model.ID == 0))
    { 
    <input type="hidden" value="@User.Identity.Name" name="WebPage.Owner" /> 
    }
    <table cellpadding="10px">
        <tr>
            <td colspan="2">@Html.ValidationSummary()
            </td>
        </tr>
        @if ((Model != null) && (Model.ID > 0))
        { 
            <tr>
                <td colspan="2" style="font-size: 150%;">
                    <table>
                        <tr>
                            <td>
                                <img src="@Url.Content("~/Content/Images/permalink.gif")" alt="permalink" />
                            </td>
                            <td>@Html.Global("RES_PERMALINK")
                            </td>
                            <td style="color: Gray">@(UrlResolver.Resolve(Context) + Url.Content(VirtualPathUtility.GetDirectory(Model.Path)))
                            </td>
                            <td style="text-decoration: underline;">
                                @{ var _slug = Path.GetFileNameWithoutExtension(VirtualPathUtility.GetFileName(Model.Path));}
                                <span id="edit_slug">@_slug</span>
                                @if (!Model.IsShared && string.IsNullOrEmpty(Model.ViewData) && !Model.Path.Equals("~/home/index") && !Model.Path.EndsWith("index.html"))
                                {
                                    <input type=hidden value="@_slug" id="Slug" name="Slug"/>
                                    Ajax.RegisterStartupScript("$(\"#edit_slug\").editable({submit:function(){ $(\"#Slug\").val($(this).text()); }});");
                                }
                            </td>
                            @if (Model.Path.EndsWith(".html"))
                            {
                                <td style="color: Gray">
                                    .html
                                </td>
                            }
                        </tr>
                    </table>
                </td>
            </tr>
        }
        <tr>
            <td id="main_fields" style="vertical-align: top;">
                <div id="title_field">
                    <h4>
                        <label for="Title">
                            @Html.Global("RES_TITLE") - @Html.Global("RES_PAGE_TITLE_TIPS")
                        </label>
                    </h4>
                    @Ajax.DnaFor().TextBox(m => m.Title).Width(450).GetHtml()
                    <div>
                        @Html.ValidationMessageFor(m => m.Title, "(" + Html.Global("RES_REQUIRED") + ")")</div>
                </div>
                <div id="keyword_field">
                    <h4>
                        <label for="Keyword">
                            @Html.Global("RES_KEYWORD")
                        </label>
                    </h4>
                    @Ajax.DnaFor().TextArea(m => m.Keywords).Width(450).GetHtml()
                </div>
                <div id="desc_field">
                    <h4>
                        <label for="Description">
                            @Html.Global("RES_DESC")</label></h4>
                    @Ajax.DnaFor().TextArea(m => m.Description).Width(450).GetHtml()
                </div>
                <div id="layout_field">
                    @if ((Model != null) && (Model.IsStatic))
                    {
                        @Html.Hidden("ViewName", "")
                    }
                    else
                    {
                        <h4>
                            @Html.Global("RES_PAGE_LAYOUT")</h4>
                        @(
 Ajax.Dna().ListBox("WebPage.ViewName")
                        .Width(455)
                        .Height(160)
                        .Select((Model == null) ? "Layout_1" : Model.ViewName)
                        .Options(opts =>
                        {
                            opts.IsInlineMode = true;
                        })
                        .ItemHtmlAttributes(new { style = "width: 110px; height: 135px; float: left; margin: 2px; border: 1px solid #cccccc;", @class = "ui-corner-all" })
                        .ItemTemplate(@<text>
                        <div>
                            <center>
                                <img src="@item.ImageUrl" alt="" /></center>
                        </div>
                        <div style="text-align: center; width: 100px; white-space: pre-line;" class="d-list-item-text">
                            @item.Title</div>
                        </text>)
                            .Items(items =>
                            {
                                items.AddValue(Html.Global("PageForm_Layout_FullSize"), "Layout_1", Url.Content("~/Content/Images/1.png"));
                                items.AddValue(Html.Global("PageForm_Layout_LeftRight"), "Layout_2", Url.Content("~/Content/Images/2.png"));
                                items.AddValue(Html.Global("PageForm_Layout_3Columns"), "Layout_3_1", Url.Content("~/Content/Images/3-1.png"));
                                items.AddValue(Html.Global("PageForm_Layout_BA2Columns"), "Layout_3_2", Url.Content("~/Content/Images/3-2.png"));
                                items.AddValue(Html.Global("PageForm_Layout_BB2Columns"), "Layout_3_3", Url.Content("~/Content/Images/3-3.png"));
                                items.AddValue(Html.Global("PageForm_Layout_4Columns"), "Layout_4_1", Url.Content("~/Content/Images/4-1.png"));
                                items.AddValue(Html.Global("PageForm_Layout_RTL2"), "Layout_4_2", Url.Content("~/Content/Images/4-2.png"));
                                items.AddValue(Html.Global("PageForm_Layout_BA3Columns"), "Layout_4_3", Url.Content("~/Content/Images/4-3.png"));
                                items.AddValue(Html.Global("PageForm_Layout_BB3Columns"), "Layout_4_4", Url.Content("~/Content/Images/4-4.png"));
                                items.AddValue(Html.Global("PageForm_Layout_LTR2"), "Layout_4_5", Url.Content("~/Content/Images/4-5.png"));
                                items.AddValue(Html.Global("PageForm_Layout_2C2B"), "Layout_4_6", Url.Content("~/Content/Images/4-6.png"));
                                items.AddValue(Html.Global("PageForm_Layout_Complex"), "Layout_4_7", Url.Content("~/Content/Images/4-7.png"));
                            }).GetHtml()
                           )
                        <div>
                            @Html.Global("RES_PAGE_LAYOUT_TIPS")
                        </div>
                    }
                </div>
            </td>
            <td id="option_fields" valign="top">
                <div id="navigateto_field">
                    <h4>
                        <label for="Title">
                            @Html.Global("RES_NAVIGATE_TO")</label></h4>
                    @Ajax.DnaFor().TextBox(m => m.LinkUrl).Width(300).GetHtml()
                    <div>
                        @Html.Global("RES_NAVIGATE_TO_TIPS")
                    </div>
                </div>
                <div>
                    <h4>
                        <label for="IconUrl">
                            @Html.Global("RES_ICON_URL")</label></h4>
                    <table>
                        <tr>
                            <td>@Ajax.DnaFor().TextBox(m => m.IconUrl).Width(300).GetHtml()
                            </td>
                            <td>@Ajax.Dna().Button("btnBrowseIcon").LocText("RES_BROWSE").Click("_fileDlg(\"#WebPage_IconUrl\");").ImageIcons(Url.Content("~/content/images/icon_folder_open_16.gif")).GetHtml()
                            </td>
                        </tr>
                    </table>
                    <div>@Html.Global("PageForm_IconUrl_Tips")
                    </div>
                </div>
                <div>
                    <h4>
                        <label for="ImageUrl">
                            @Html.Global("RES_IMAGEURL")</label></h4>
                    <table>
                        <tr>
                            <td>@Ajax.DnaFor().TextBox(m => m.ImageUrl).Width(300).GetHtml()
                            </td>
                            <td>@Ajax.Dna().Button("btnBrowseImages").LocText("RES_BROWSE").Click("_fileDlg(\"#WebPage_ImageUrl\");").ImageIcons(Url.Content("~/content/images/icon_folder_open_16.gif")).GetHtml()
                            </td>
                        </tr>
                    </table>
                    <div>@Html.Global("PageForm_ImageUrl_Tips")
                    </div>
                </div>
                <div id="target_field">
                    <h4>
                        @Html.Global("RES_TARGET")</h4>
                    @(
 Ajax.Dna().ComboBox("WebPage.Target")
                       .DropDownList()
                       .Width(200)
                       .Select(Model == null ? "_self" : (!string.IsNullOrEmpty(Model.Target)) ? Model.Target : "_self")
                       .Items(items =>
                       {
                           items.AddValue(Html.Global("RES_TARGET_BLANK"), "_blank");
                           items.AddValue(Html.Global("RES_TARGET_PARENT"), "_parent");
                           items.AddValue(Html.Global("RES_TARGET_SELF"), "_self");
                           items.AddValue(Html.Global("RES_TARGET_TOP"), "_top");
                       })
                       .GetHtml()
                    )
                    <div>
                        @Html.Global("RES_TARGET_TIPS")
                    </div>
                </div>
                <div id="showInmenu_field" style="margin-top: 10px;">
                    @(Ajax.Dna().Checkbox("WebPage.ShowInMenu", Html.Global("RES_SHOW_IN_MENU"), Model == null ? true : Model.ShowInMenu,
                           Url.Content("~/content/images/icon_accept_16.png"),
                           Url.Content("~/content/images/icon_block_16.png"))
                           .Options(opts =>
                           {
                               opts.OnStateChanged = "if (value) { $('#TargetRow').show();$('#ParentPageRow').show();}else{$('#TargetRow').hide(); $('#ParentPageRow').hide(); }";
                           })
                           .GetHtml()
                    )
                    <span>-@Html.Global("RES_SHOWINMENU_TIPS")</span>
                </div>
                <div id="parentPage_field">
                    <h4>
                        @Html.Global("RES_PARENT_PAGE")</h4>
                    @{ var combo = Ajax.Dna().ComboBox("WebPage.ParentID")
                           .Width(280)
                           .Options(opts =>
                           {
                               if (Model != null)
                               {
                                   var _parentPage = WebSiteContext.Current.DataContext.WebPages.Find(Model.ParentID);
                                   if (_parentPage != null)
                                   {
                                       opts.Value = _parentPage.ID.ToString();
                                       opts.Text = _parentPage.Title;
                                   }
                                   else
                                   {
                                       opts.Value = "0";
                                       opts.Text = context.Web.Title;
                                   }
                               }
                               else
                               {
                                   opts.Value = "0";
                                   opts.SelectedValue = "0";
                                   opts.Text = context.Web.Title;
                               }
                           })
                           .DropDownStyle(DropdownStyles.DropdownList)
                           .DropDownContent(() =>
                           {
                               Ajax.Dna().TreeView("SiteMapTree")
                                   .SinglePathExpand(true)
                                        .Options(opts =>
                                        {
                                            opts.OnNodeSelected = "$(\"#WebPage_ParentID\").combo(\"setValue\",$(\">.d-treenode-content\",$(node)).find(\".d-treenode-text\").text(),$(node).attr(\"key\"));";
                                        })
                                   .Bind(context.SiteMapNodeProvider.RootNode, (node) =>
                                   {
                                       node.NavigateUrl = "javascript:void(0);";
                                       node.ImageUrl = Url.Content("~/content/images/icon_aspx_16.png");
                                       return true;
                                   })
                                   .Render();
                           });

                       combo.Render();
                    }
                    <div>
                        @Html.Global("RES_PARENT_PAGE_TIPS")
                    </div>
                </div>
                <div id="security_fields">
                    <div id="anonymous_field" style="margin-top: 10px;">
                        @( 
 Ajax.Dna().Checkbox("WebPage.AllowAnonymous", Html.Global("RES_ALLOW_ANONYMOUS"), Model == null ? true : Model.AllowAnonymous,
                           Url.Content("~/content/images/icon_accept_16.png"),
                           Url.Content("~/content/images/icon_block_16.png"))
                           .Options(opts =>
                           {
                               opts.OnStateChanged = "if (value) $('#securityroles_field').hide(); else $('#securityroles_field').show();";
                           })
                           .GetHtml()
                           )
                        <span>-@Html.Global("RES_ALLOW_ANONYMOUS_TIPS") </span>
                    </div>
                    <div id="securityroles_field">
                        @if ((Model == null) || (Model.AllowAnonymous))
                        {
                            Html.RegisterStartupScript("$('#securityroles_field').hide();");
                        }
                        <div style="margin-top: 10px; margin-bottom: 5px;">
                            ( @Html.Global("RES_ALLOW_PERSONLIZIATION_TIPS") )
                        </div>
                        @if ((Model == null) || Model.ID == 0 || (Model.AllowAnonymous))
                        {
                            @Ajax.Dna().ListBox("AccessableRoles").HtmlAttributes(new { style = "border:none;" }).ShowCheckbox().Bind(Roles.GetAllRoles()).GetHtml()
                        }
                        else
                        { 
                            @(Ajax.Dna().ListBox("AccessableRoles").HtmlAttributes(new { style = "border:none;" })
                        .Select(Model.Roles.Select(r => r.RoleName).ToArray())
                        .ShowCheckbox().Bind(Roles.GetAllRoles()).GetHtml())
                        }
                    </div>
                </div>
            </td>
        </tr>
    </table>
    <hr />
    <div style="padding-top: 10px; padding-bottom: 10px; text-align: center">
        @Ajax.Dna().Button("btnSiteSettingSubmit").ImageIcons(Url.Content("~/content/images/icon_save.gif")).LocText("RES_SAVE").Submit().GetHtml()
        @if ((Model != null) && (Model.ID > 0))
        {
 
            @(
 Ajax.Dna().Button("btnDeletePage")
                           .ImageIcons(Url.Content("~/content/images/icon_delete_16.png"))
                           .LocText("RES_DELETE")
                           .Click(Ajax.GeneratejQueryAjaxScripts(new jQueryAjaxOptions()
                           {
                               HttpMethod = "POST",
                               Confirm = Html.Global("PageForm_ConfirmDelete"),
                               Url = Url.Action("Delete", "DynamicUI", new { id = Model.ID }),
                               OnSuccess = "window.location='" + (!string.IsNullOrEmpty(Request.QueryString["returnUrl"]) ? (Server.UrlDecode(Request.QueryString["returnUrl"])) : (context.Web.IsRoot ? Url.Content("~/") : Url.Content("~/sites/" + context.Web.Name + "/index.html"))) + "';"
                           }))
                           .GetHtml()
            )
            if (!Model.IsStatic)
            {
                Ajax.Dna().Button("btnExportPageData" + Model.ID.ToString())
                               .LocText("RES_EXPORT")
                               .Click("window.open(\"" + Url.Action("Export", "DynamicUI", new { Area = "", website = context.Web.Name, id = Model.ID }) + "\");")
                               .ImageIcons(Url.Content("~/content/images/icon_download_16.gif"))
                               .Render();
            }
        }
        @if (!string.IsNullOrEmpty(Request.QueryString["returnUrl"]))
        { 
            @Ajax.Dna().Button("btnReturn").LocText("RES_CANCEL").Click("location='" + Request.QueryString["returnUrl"] + "';").ImageIcons(Url.Content("~/content/images/icon_back_16.png")).GetHtml()
        }
                    @Ajax.Dna().Link(Html.Global("RES_HELP"), Url.Help(1), Url.Content("~/content/images/help.png")).Options(opts => { opts.Target = "_blank"; }).GetHtml()
    </div>
}
<script type="text/javascript">
    function _fileDlg(_el) {
      $dna.fileDlg("@Url.Action("Dialog", "WebFiles", new { Area = "", website = context.Web.Name })", _el);
    }
</script>
@Html.StartupScripts()
